<?php

require_once 'model/place.class.php';

//require_once 'config/mySqlConfig.php';
//require_once 'dao/opendb.dao.php';
require_once('dao/database.dao.php');

class placeFromSql{

function findPlaceName($name){
	$db = database::connect();
    
	$name = utf8_decode($name);
 	$query  = "SELECT * FROM places Where Stadnamn='$name' or Kommune='$name' order by prioritet";
    
    $result = mysql_query($query) or DIE(mysql_error());

	$row = mysql_fetch_row($result);
	//database::disconnect($db);;
	if (count($row) === 0){
		return null;
	} else { //if (count($row) === 1){
		$name = $row[2];
		$lat  = $row[6];
		$long = $row[7];

		$place = new PlaceModel($name,$lat,$long);
	 	return $place;
	}/** else {
		$places = array();
		foreach($row as $rw){
			$name = $rw[2];
			$lat  = $rw[6];
			$long = $rw[7];

			$places[] = new PlaceModel($name,$lat,$long);
		}
		return $places;
	}*/
}

function findPlaceId($id){
	$db = database::connect();

	$query  = "SELECT * FROM places Where id='$id'";
	$result = mysql_query($query);

	$row = mysql_fetch_row($result);

	$name    = $row[2];
	$lat = $row[6];
	$long = $row[7];

	$place = new PlaceModel($name,$lat,$long);
	 
	database::disconnect($db);
	return $place;
}

}
//findPlaceName("Bergen");
//require_once 'closedb.dao.php';
?>